<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>命名路由和命名视图</title>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
    <style>
        ul {
            list-style-type: none;
        }

        li {
            float: left;
            width: 150px;
        }

        li a {
            text-decoration: none;
        }

        .show {
            clear: both;
            margin-top: 50px;
        }
    </style>
</head>

<body>
    <template id="t1">
        <div>
            <h2>热点新闻</h2>
        </div>
    </template>
    <template id="t2">
        <div>
            <h2>推荐信息</h2>
        </div>
    </template>
    <template id="t3">
        <div>
            <h2>军事快报</h2>
        </div>
    </template>

    <div id="app">
        <div>
            <li>
                <router-link :to="{name:'index1'}">首页</router-link>
            </li>
            <li>
                <router-link :to="{name:'news1'}">新闻</router-link>
            </li>
        </div>
        <div class="show">
            <router-view name="first" style="background-color: chartreuse;"></router-view>
            <router-view name="second" style="background-color: darkgoldenrod;"></router-view>
        </div>
    </div>
    
</body>

</html>
<script>
    var vm = new Vue({
        el: "#app",
        router: new VueRouter({
            routes: [
                {
                    path: "/index",
                    name: "index1",
                    components: {
                        first: {
                            template:"#t1"
                        },
                        second: {
                            template:"#t2"
                        },
                        
                    }
                },
                {
                    path: "/news",
                    name: "news1",
                    components: {
                        second: {
                            template:"#t3"
                        }
                    }
                }
            ]
        })
    });
</script>